import React from 'react';

import BaseAction from '../common/BaseAction';
import Constants from '../../common/Constants';
import ResponseConstants from '../../common/ResponseConstants';

export default class ActivityRequestEnterAction extends BaseAction{
  constructor() {
      super();

      this.moduleType = Constants.MODULE_TYPE.ACTIVITY;
      this.name = "ActivityRequestEnterAction";
  }

  call(caller, data) {
      this._baseCall(caller, data);
      this.caller.setState({
        enter_state: 1,
      })
  }

  //enter_state:0初始化|已取消报名,1请求中,2已报名,3失败, 数据}
  finish(data, isSucceed, response) {
    let enter_state = 0;
    let statusText = "";
    let dealText = this.data.type == "enter" ? "报名" : "取消报名";
    if(response.status == ResponseConstants.status_conflict) {
      // enter_state = this.data.type == "enter" ? 2 : 0;
      statusText = "不能重复" + dealText;
      enter_state = 2;
    }
    else if(response.status == ResponseConstants.status_created_success || response.status == ResponseConstants.status_deal_success){
      statusText = dealText + "成功";
      enter_state = 2;
      // enter_state = this.data.type == "enter" ? 2 : 0;
    }
    else if(response.status == ResponseConstants.status_unauthorized){
      this._dealUnauthorized(this.caller);
    }
    else {
      statusText = dealText + "失败 " + response.status;
      enter_state = 2;
    }
    this.caller.setState({
      enter_state: enter_state,
      statusText:statusText,
      viewState:response.status,
    })
  }
}
